package org.freedoit.server.service.task;

import java.util.logging.Logger;

import org.freedoit.common.data.FreeDoitTaskResponse;
import org.freedoit.common.shared.SharedTask;
import org.freedoit.server.om.Task;
import org.freedoit.server.service.ServiceManager;
import org.freedoit.server.util.Utils;

public class AddTaskServlet extends AbstractTaskServletImpl {

	/**
	 * 
	 */

	private static final Logger log = Logger.getLogger(AddTaskServlet.class.getName());
	private static final long serialVersionUID = -4511087566999049359L;

	protected void workOnTask(SharedTask sharedTask, Long currentUserId, Long currentClientId, FreeDoitTaskResponse result,
			Long timestamp) {
		// TODO Auto-generated method stub
		Task task = Utils.fromSharedData(sharedTask);
		System.out.println("Task Name:" + task.getTaskName());
		if (ServiceManager.addNewTask(task, currentUserId, currentClientId, null, null, timestamp)) {
			System.out.println("Task id:" + task.getTaskId());
			result.setCode(FreeDoitTaskResponse.CODE_OK);
			result.setTimestamp(timestamp.longValue());
			result.setTaskID(task.getTaskId());
		} else {
			result.setCode(FreeDoitTaskResponse.CODE_INVALID_DATA);
		}

		log.warning("" + result.getCode());
	}

}
